
import matplotlib.pyplot as plt

# 创建画布
plt.rcParams["font.sans-serif"]=["SimHei"]  # 设置字体
plt.rcParams["axes.unicode_minus"]=False    # “-”负号的显示
fig = plt.figure(figsize=(30,30), dpi=20)   # 空的画布
ax = fig.add_subplot(111)                   # 创建2d绘图区域
ax.tick_params(labelsize=8)                 # 刻度字体

# 数据
def line(x1,x2, y1,y2):
    length = abs(y2-y1) if abs(y2-y1)>=abs(x2-x1) else abs(x2-x1)
    delta_x = (x2-x1)/length; delta_y = (y2-y1)/length
    k = 1
    x = x1; y = y1
    pts_x = []; pts_y = []
    while k <= length+1:
        pts_x.append(x); pts_y.append(y)
        k += 1
        x += delta_x; y += delta_y
    return pts_x,pts_x 

x,y = line(-100,100, 76,-40)

# 绘图
ax.scatter(x, y, s = 20)          # 绘制（散点图）
ax.set_title('直线', fontsize=90) # 标题

# 参考线
def axs(xx=(-1,1),yx=(-1,1)): 
    color = ['r', 'g']
    for i,t in  enumerate((xx, yx)):
        xs = [(0,0), (0,0)]
        f = True if t[0]<0 and t[1]>0 else False
        if f:
            xs[i] = (t[0], 0)
            ax.plot(xs[0], xs[1], linestyle=':', color=color[i])
            xs[i] = (0, t[1])
            ax.plot(xs[0], xs[1], linestyle='-', color=color[i])
        else: 
            xs[i] = (t[0], t[1])
            ax.plot(xs[0], xs[1], linestyle='-', color=color[i])
axs(xx=(-100,100), yx=(-100,100))

# 显示窗口
plt.show()